//
//  OSMyOrderVC.m
//  ZKPayApp
//
//  Created by 凯朱 on 2024/10/31.
//

#import "OSMyOrderVC.h"
#import "OSMyOrderCell.h"

static  NSString *const kCellId = @"OSMyOrderCell";
@interface OSMyOrderVC ()<UITableViewDelegate,UITableViewDataSource>{
    NSDictionary *_applyInfo;
}
@property (nonatomic, strong)NSMutableArray *dataArray;
@property (nonatomic, strong)UITableView *tableView;
@end

@implementation OSMyOrderVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [OSTool showHudOnWindow];
    [self.dataArray removeAllObjects];
    [OSHttpManager postWithPath:@"appInfo" params:nil finished:^(BOOL isSuccessed, id result, NSString *code, NSString *message) {
        [OSTool hideHudOnKeyWindow];
        NSString *key = [NSString stringWithFormat:@"curOrder_%@",kUserInfo.user_id];
        self->_applyInfo = [[NSUserDefaults standardUserDefaults] objectForKey:key];
        if (self->_applyInfo) {
            [self.dataArray addObject:self->_applyInfo];
        }
        [self->_tableView reloadData];
    }];
    [self.view addSubview: self.tableView];
}



#pragma mark - ================<tableViewDataSource>===============
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    OSMyOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId];
    NSDictionary *info = _dataArray[indexPath.row];
    cell.noLbl.text = [NSString stringWithFormat:@"%@：%@",kLocalString(@"订单"),info[@"id"]];
    cell.statuLbl.text = kLocalString(@"等待放款");
    cell.timeLbl.text = [NSString stringWithFormat:@"%@：%@",kLocalString(@"申请日期"),info[@"creatDate"]];
    cell.moneyLbl.text = [NSString stringWithFormat:@"%@：%@",kLocalString(@"申请金额"),info[@"money"]];
    return cell;
}

#pragma mark - ================<UITableViewDelegate>===============
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UITableViewHeaderFooterView *headview = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"head"];
    if (!headview) {
        headview = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"head"];
        headview.frame = CGRectMake(0, 0, kScreenWidth, 0.1);
        headview.contentView.backgroundColor = kClearColor;
    }
    return headview;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UITableViewHeaderFooterView *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"foot"];
    if (!footerView) {
        footerView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"foot"];
        footerView.frame = CGRectMake(0, 0, kScreenWidth, 0.1);
        footerView.contentView.backgroundColor = kClearColor;
    }
    return footerView;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - ================<懒加载>===============
-(UITableView *)tableView{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight+15,kScreenWidth,kScreenHeight-SafeAreaTopHeight-SafeAreaBottomHeight) style:UITableViewStyleGrouped];
        _tableView.estimatedRowHeight = 80;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerNib:[UINib nibWithNibName:kCellId bundle:nil] forCellReuseIdentifier:kCellId];
        _tableView.backgroundColor = kClearColor;
    }
    return _tableView;
}

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}
@end
